<?php
namespace app\school\controller;
use think\Controller;
use think\Db;
use think\Session;
class School extends Controller
{
    public function index()
    {
        
        $school_id = Session::get('school_id');
        $school_name =Db::name('school')->where('school_id',$school_id)->find();
        $xi1 = Db::name('user')->where('user_school',$school_name['school_name'])->limit(1)->find();
        // dump($xi1['user_major']);
        // exit;
        $res = Db::name('user')->where('user_school',$school_name['school_name'])->where('user_major',$xi1['user_major'])->select();
        
        $this->assign("res",$res);
        $res1 = Db::name('company')->where('company_status',0)->select();
        // dump($res);
        // exit;
        $this->assign("res1",$res1);
        $xi = Db::name('user')->where('user_school',$school_name['school_name'])->field('user_major')->group('user_major')->select();
        // dump($xi);
        // exit;
        $this->assign("xi",$xi);
        return $this->fetch();
    }

    public function index1($user_major)
    {
        $school_id = Session::get('school_id');
        $school_name =Db::name('school')->where('school_id',$school_id)->find();
       $res = Db::name('user')->where('user_school',$school_name['school_name'])->where('user_major',$user_major)->select();
        
        $this->assign("res",$res);
        $res1 = Db::name('company')->where('company_status',0)->select();
        // dump($res);
        // exit;
        $this->assign("res1",$res1);
        $xi = Db::name('user')->where('user_school',$school_name['school_name'])->field('user_major')->group('user_major')->select();
        // dump($xi);
        // exit;
        $this->assign("xi",$xi);
        return $this->fetch();
    }

    public function nt($user_id,$company_id)
    {
        $school_id = Session::get('school_id');
        $data = [
            "user_id"=>$user_id,
            "company_id"=>$company_id,
            "school_id"=>$school_id,
            "nt_status"=>0,
            "nt_time"=>date('Y-m-d H:i:s',time()),

        ];
        // dump($data);
        // exit;
        $cc = Db::name('nt')->where('user_id',$user_id)->where('school_id',$school_id)->where('company_id',$company_id)->find();
        // dump($res);
        // exit;
        if($cc==null){

            $res = Db::table('nt')->insert($data);
                if($res)
                {
                    return $this->success('内推成功','school/index');
                }
                else
                {
                    return $this->error('失败');
                }
            
        }else{
            return $this->error('已经内推过啦');
        }
    }
}